Use Morph resource to change one shape into another through a seamless transition. Kanzi uses shaders to enable morphing.
To morph between shapes in Kanzi you need to:
When you create 3D models in your third-party tool between which you want to morph, first create the base model and then from that model shape the model to which you want to morph. When creating the models keep in mind:
To morph meshes:
attribute vec3 kzPosition; attribute vec3 kzNormal;
with
attribute vec3 kzMorphTarget0Position; attribute vec3 kzMorphTarget1Position; attribute vec3 kzMorphTarget0Normal; attribute vec3 kzMorphTarget1Normal;
To morph between more than two meshes, add as many kzMorphTargetPosition
and kzMorphTargetNormal
attributes as you have meshes between which you want to morph.
uniform mediump float kzMorphWeights[2];
To morph between more than two meshes, set the kzMorphWeights
to the number of meshes between which you want to morph.
main()
function instead ofvec4 positionWorld = kzWorldMatrix * vec4(kzPosition.xyz, 1.0);
use
vec3 position = kzMorphTarget0Position * kzMorphWeights[0] + kzMorphTarget1Position * kzMorphWeights[1]; vec4 positionWorld = kzWorldMatrix * vec4(position.xyz, 1.0); vec3 V = normalize(positionWorld.xyz - kzCameraPosition); vec3 normal = normalize( (kzMorphTarget0Normal * kzMorphWeights[0]) + (kzMorphTarget1Normal * kzMorphWeights[1]) );
To morph between more than two meshes, adjust the kzMorphTargetPosition
, kzMorphWeights
, and kzMorphTargetNormal
values accordingly.
main()
function replacevec4 N = kzNormalMatrix * vec4(kzNormal, 1.0); vNormal = N.xyz; gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
with
vec4 N = kzNormalMatrix * vec4(kzNormal, 1.0); vNormal = N.xyz; gl_Position = kzProjectionCameraWorldMatrix * vec4(position.xyz, 1.0);
To add meshes to a Morph: